package com.example.springboot_demo01.controller;

import com.example.springboot_demo01.entity.Score;
import com.example.springboot_demo01.entity.form.ScoreForm;
import com.example.springboot_demo01.entity.form.ScoreItem;
import com.example.springboot_demo01.service.ScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RestController
@RequestMapping("/score")
@Api(tags = "成绩管理接口")
public class ScoreController {
    @Resource
    ScoreService scoreService;

    @ApiOperation("成绩录入保存---实现将某门课的某个班所有学生的成绩批量录入保存")
    @PostMapping("/add")
    // @RequestBody  ---前端以json格式传递数据过来，接收后转成一个对象
    public int  add( @RequestBody  ScoreForm scoreForm){
        /*
        //验证前端输入的数据是否正常被接收
        System.out.println("courseId:"+ scoreForm.getCourseId());
        for(ScoreItem item:scoreForm.getScoreItemList())
            System.out.println("studentId:" + item.getStudentId()
                              +"point:"     + item.getPoint()
            );
         */
         scoreService.add(scoreForm);
         return  1;
    }

    @ApiOperation("根据班级id和课程id获得学生成绩列表")
    @GetMapping("/getScoreListByClassAndCourse")
    public List<Score> getScoreListByClassAndCourse(int classId,
                                                    int courseId){
        return scoreService.getScoreListByClassAndCourse(classId,courseId);
    }

    @ApiOperation("某个班级 某门课程的成绩分析")
    @GetMapping("/getReportByClassAndCourse")
    public Map getReportByClassAndCourse(int classId,
                                         int courseId){
         return scoreService.getReportByClassAndCourse(classId,courseId);
    }


    @ApiOperation("某门课程 各个班级的成绩分析")
    @GetMapping("/getReportByCourse")
    public List<Map> getReportByCourse( int courseId){
        return scoreService.getReportByCourse(courseId);
    }

}
